package com.prime.tutorial.moviestore.dao;

import com.prime.tutorial.moviestore.domain.Country;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

@Repository
public class CountryDAOWithJPA extends GenericDAOWithJPA<Country, Long> implements CountryDAO {

    //	@SuppressWarnings("unchecked")
    public List<Country> findByName(String name) {
        Query query = entityManager.createQuery("Select distinct m from Country m where m.name = ?1");
        query.setParameter(1, name);
        return query.getResultList();
//		return getJpaTemplate().find("Select m from Groups m where m.name = ?1",name);
    }

    public List<Country> findWithDevices() {
        Query query = entityManager.createQuery("Select distinct co from Country co, Location l, Device d where d.location = l.id and l.country = co.id");
        return query.getResultList();
    }
}